@extends('admin.main')

@section('content')
<div class="row wrapper border-bottom white-bg page-heading">
	<div class="col-sm-4">
		<h2>{{$perm->display_name}} <small>{{$perm->name}}</small></h2>
		<strong>{{$perm->description}}</strong>
	</div>
</div>
<div class="wrapper wrapper-content">
	<div class="m-b">
		<a href="{{session('listUrl')}}" class="btn btn-default"><i class="fa fa-arrow-left"></i> 返回列表</a>
	</div>
	<div class="ibox float-e-margins">
		<div class="ibox-title">
			<h5>含有 <span class="text-danger">{{$perm->display_name}}</span> 操作权限的角色列表如下：<small>请勾选为其授权</small></h5>
		</div>
		<div class="ibox-content">
			<table id="tblDataList" class="table table-hover table-bordered">
				<thead>
					<tr>
						<th width="60"><a href="javascript:;" onclick="checkAll()">全选</a></th>
						<th>名称</th>
						<th>全名</th>
						<th>描述</th>
					</tr>
				</thead>
				<tbody>
					@foreach($roles as $row)
					<tr data-id="{{$row->id}}">
						<td class="text-center">
							<label class="i-checks">
								<input type="checkbox" value="{{$row->id}}" class="js-check" {{ in_array($row->id, $cur_role_ids) ? 'checked=""' : '' }} />
							</label>
						</td>
						<td>{{$row->name}}</td>
						<td>{{$row->fullname}}</td>
						<td>{{$row->description}}</td>
					</tr>
					@endforeach
				</tbody>
			</table>
		</div>
	</div>
</div>
@endsection

@section('pageheader')
<link href="{{asset('assets/css/plugins/iCheck/custom.css')}}" rel="stylesheet">
@endsection

@section('pagescript')
<script src="{{asset('assets/js/plugins/iCheck/icheck.min.js')}}"></script>
<script src="{{asset('assets/models/roleModel.js')}}"></script>
<script>
	var artDialog, perm_id='{{$id}}';
	$("#sidebar li[rel='entrust']").addClass("active")
		.find("ul").addClass("in")
		.find("li[rel='3']").addClass("active");

	$('.i-checks').iCheck({
    checkboxClass: 'icheckbox_square-green',
    radioClass: 'iradio_square-green',
  });

  var checkAll = function(){
    $(".js-check").iCheck("check");
  };

  $(".js-check").on('ifChanged', function(){
  	var checked = $(this).prop("checked");
  	if(checked){
	 		roleModel.addPerm({'id':$(this).val(),'perm_id':perm_id}, null, failure);
	 	}else{
	 		roleModel.removePerm({'id':$(this).val(),'perm_id':perm_id}, null, failure);
	 	}
  });

	var failure = function(data){
		dialog({content:'<i class="fa fa-info-circle"></i> '+data.responseJSON}).showModal();
	};
</script>
@endsection